package com.scuec.groupfive.mapper;

import com.scuec.groupfive.entity.UserPostFavorite;
import org.apache.ibatis.annotations.*;

@Mapper
public interface UserPostFavoriteMapper {

    @Select("SELECT is_favorite FROM posts WHERE post_id = #{post_id}")
    Integer checkPostFavoriteStatus(@Param("post_id") Long post_id);

    @Insert("INSERT INTO post_favorites (post_id, user_id, created_at, status) " +
            "VALUES (#{post_id}, #{user_id}, NOW(), 1)")
    void insertFavorite(UserPostFavorite favorite);

    @Update("UPDATE post_favorites SET status = 0 " +
            "WHERE post_id = #{post_id} AND user_id = #{user_id}")
    void updateStatusToInactive(@Param("post_id") Long post_id, @Param("user_id") Long user_id);
}